package com.wdd.libhttp.http

import com.lzy.okgo.convert.Converter
import okhttp3.Response

/**
 *
 * @ProjectName:    OwnTool
 * @Package:        com.wdd.libbase.http
 * @ClassName:      StringConvert
 * @Description:     字符串转换,有加解密封装
 * @Author:         王丹丹
 * @CreateDate:     2019/12/9 16:41
 * @UpdateUser:     更新者
 * @UpdateDate:     2019/12/9 16:41
 * @UpdateRemark:   更新说明
 * @Version:        1.0
 */
class StringConvert constructor(private val encryptionImp: EncryptionInterface?) :
    Converter<String> {

    constructor() : this(null)

    @Throws(Throwable::class)
    override fun convertResponse(response: Response): String? {
        val body = response.body() ?: return null
        var content = body.string()

        if (encryptionImp != null) {
            content = encryptionImp.decodeData(content)
        }

        return content
    }
}